import sys

sys.path.append(r"/data/finance.Source/utils")
sys.path.append(r"/data/finance.Source/Analysis/strategy")
sys.path.append(r"/data/finance.Source/Analysis/strategy/config")

import bigbuysell
import runBuySell
import datetimeutils
import selectsql

# runBuySell.getonedayScore(bigbuysell.TA,-7)
codeitem = {
    "n100":{
        'table': 'zc_tickkz',
        'code': 'CF905',
        'xlcode': 'CF1905',
        'name': '棉花1905',
        'bigNum': '100',
        'zb':0.04
    },
    "n300":{
        'table': 'zc_tickkz',
        'code': 'CF905',
        'xlcode': 'CF1905',
        'name': '棉花1905',
        'bigNum': '200',
        'zb':0.03
    },
    "n500":{
        'table': 'zc_tickkz',
        'code': 'CF905',
        'xlcode': 'CF1905',
        'name': '棉花1905',
        'bigNum': '400',
        'zb':0.015
    },
    "n1000":{
        'table': 'zc_tickkz',
        'code': 'CF905',
        'xlcode': 'CF1905',
        'name': '棉花1905',
        'bigNum': '800',
        'zb':0.005
    }
}
# 当天回测
def testonedays(codeitem,mdays):
    allNum = 0
    buynum = 0   # 做多次数
    sellnum = 0  # 做空次数
    sNum = 0  # 成功次数
    eNum = 0  # 失败次数
    while mdays < 0:
        mdays += 1
        lastdate = datetimeutils.getlastday(mdays)
        dkdata = selectsql.selectonedayDKline(codeitem["n100"]['xlcode'],lastdate)
        if len(dkdata) > 0:
            onedayScore = runBuySell.getonedayScore(codeitem,mdays)
            allNum += 1
            if onedayScore < -60:
                sellnum += 1
                print(codeitem["n100"]["name"],'做空')
            elif onedayScore > 60:
                print(codeitem["n100"]["name"],'做多')
                buynum += 1

    allNum = buynum+sellnum
    print("交易次数",allNum)
    return allNum

testonedays(codeitem,-10)


#def testmoredays()



